package com.twp.auth.domain.authority;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.twp.auth.domain.authority.user.ManageUser;
import lombok.*;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;

@EqualsAndHashCode(
        exclude = {
                "menuList","manageUserList"
        }
)
@ToString(
        exclude = {
                "menuList","manageUserList"
        }
)
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
@Table(name = "twp_role")
public class Role implements java.io.Serializable{
    /**
     * 编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    /**
     * 角色名称
     */
    private String roleName;
    /**
     * 角色编码
     */
    private String roleCode;
    /**
     * 0无效，1有效
     */
    private Boolean status;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "createTime")
    private Date createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "updateTime")
    private Date updateTime;

    /**
     * 修改人
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "updateUser")
    private String updateUser;

    @Transient
    private String createTimeStr;
    @Transient
    private String updateTimeStr;


    @JsonIgnore
    @JoinTable(name="twp_role_menu",//中间表的名称
            joinColumns={@JoinColumn(name="roleId",referencedColumnName="ID")},//中间表PRODUCT_ID字段关联PRODUCT的ID
            inverseJoinColumns={
                        @JoinColumn(name="menuId",referencedColumnName="ID")
            })//中间表CATEGORY_ID字段关联CATEGORY的ID
    @ManyToMany(fetch = FetchType.LAZY)
    private Set<Menu> menuList;


    @JsonIgnore
    @JoinTable(name="twp_role_user",//中间表的名称
            joinColumns={@JoinColumn(name="roleId",referencedColumnName="ID")},//中间表PRODUCT_ID字段关联PRODUCT的ID
            inverseJoinColumns={
                    @JoinColumn(name="manageUserId",referencedColumnName="ID")
            })//中间表CATEGORY_ID字段关联CATEGORY的ID
    @ManyToMany(fetch = FetchType.LAZY)
    private Set<ManageUser> manageUserList;

//    @Transient
//    private String menuIds;

    @Transient
    private boolean _checked = false;

    @Transient
    private boolean expand = true;



}